import axios from "axios";
import {getToken} from '@/utils/auth';
import fa from "element-ui/src/locale/lang/fa"; //引入axios
const instance = axios.create({
  timeout: 3600000, // 超时时间1个小时
});
// let baseURL = process.env.BASE_URL.toString();
//这里根据自己项目接口的位置自行设定
// let baseURL = "http://172.16.2.232:8098";
// let baseURL = "https://centertest.baiyiyl.com:8888";
// let baseURL = "https://center.baiyiyl.com:8888/baiyi";
let baseURL = process.env.VUE_APP_BASE_PATH;
/*if (process.env.NODE_ENV == "production") {
  baseURL = "http://1xx.1xx.1xx.1xx/hyr";
}*/
instance.defaults.baseURL = baseURL; //baseURL用于自动切换本地环境接口和生产环境接口
instance.defaults.headers.post["Content-Type"] ="application/x-www-form-urlencoded;charset=UTF-8";
instance.defaults.headers.post["Access-Control-Allow-Origin"] = "*";
instance.defaults.headers.post["token"]=getToken();
instance.defaults.withCredentials = false // 携带cookie
//上传附件axios接口封装
const upload ={
  uploadFile(url, formData, cancelToken, cd) {
    return instance({
      url: url,
      method: "post",
      data: formData,
      onUploadProgress: function(progressEvent) {
        console.log("进度：");
        console.log(progressEvent);
        if (progressEvent.lengthComputable) {
          cd(progressEvent);
        }
      },
      cancelToken: cancelToken,
    });
  },
}
export {
  upload,
  axios,
}
